{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3bacb13c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[11, 4, 15, 9, 21, 5, 13, 7, 20, 22, 3, 8, 17, 14, 0, 19, 12, 24, 16, 2, 23, 18, 1, 6, 10]\n",
      "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n",
      "2\n",
      "22\n",
      "6\n",
      "13\n",
      "1\n",
      "-*100\n",
      "14\n",
      "5\n",
      "17\n",
      "[[ 0 -1 -1  0  0]\n",
      " [10 -1  0  0  0]\n",
      " [ 0  0  0 -1 10]\n",
      " [ 0  0 10  0  0]\n",
      " [ 0  0 -1  0  0]]\n",
      "[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import random\n",
    "\n",
    "# 初始化基本参数\n",
    "rows = 5\n",
    "columns = 5\n",
    "forbiddenAreaNums = 5  # 禁止区域的数量\n",
    "forbiddenAreaScore = -1  # 禁止区域的惩罚分数\n",
    "targetNums = 3  # 目标区域的数量\n",
    "score = 10  # 目标区域的奖励分数\n",
    "\n",
    "l = [i for i in range(rows*columns)]\n",
    "\n",
    "random.shuffle(l)  # 用shuffle来重排列\n",
    "print(l)\n",
    "# 设置随机数种子\n",
    "random.seed(12)\n",
    "# 生成从0到rows*columns-1的列表\n",
    "l = [i for i in range(rows * columns)]\n",
    "# 随机打乱列表顺序，目的是随机生成禁止区域和目标区域的位置\n",
    "random.shuffle(l)  # 用shuffle来重排列\n",
    "# 初始化得分列表\n",
    "g = [0 for i in range(rows * columns)]\n",
    "# 设置禁止进入的区域得分\n",
    "print(g)\n",
    "for i in range(forbiddenAreaNums):\n",
    "    g[l[i]] = forbiddenAreaScore  # 设置禁止进入的区域，惩罚为1\n",
    "    print(l[i])\n",
    "# 设置目标区域得分\n",
    "print('-*100')\n",
    "for i in range(targetNums):\n",
    "    g[l[forbiddenAreaNums + i]] = score  # 奖励值为1的targetAre\n",
    "\n",
    "    print(l[forbiddenAreaNums + i])\n",
    "# 将得分列表转换为numpy数组并调整形状\n",
    "scoreMap = np.array(g).reshape(rows, columns)\n",
    "print(scoreMap)\n",
    "# 生成状态映射表，是一个二维列表\n",
    "stateMap = [[i * columns + j for j in range(columns)] for i in range(rows)]\n",
    "print(stateMap)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
